//---------------------------------------------------------------------
// This file is part of the Microsoft BizTalk Server 2006 SDK
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is intended only as a supplement to Microsoft BizTalk
// Server 2006 release and/or on-line documentation. See these other
// materials for detailed information regarding Microsoft code samples.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//---------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Diagnostics;

namespace MsPartners.Unisys.BizTalkAdapters.AdapterWizard
{
	public class WzPageTransmitSetup : Microsoft.BizTalk.Wizard.WizardInteriorPage, IWizardControlInterface
	{
		public event AddWizardResultEvent addWizardResultEvent;

		private const string aliasesRegEx = @"[\w]://([,][s][\w]://)*$";
		private System.Windows.Forms.CheckBox chkSolRspSupport;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtTransmitAdapterDesc;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtAliases;
		private System.Windows.Forms.ErrorProvider ErrProv;
		private RadioButton chcExtendedBatchSupport;
		private RadioButton chcSimpleBatchSupport;
		private GroupBox grpBatchSupport;
		private System.ComponentModel.IContainer components = null;

		public WzPageTransmitSetup()
		{
			// This call is required by the Windows Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitializeComponent call
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		protected void AddWizardResult(string strName, string strValue)
		{
			PropertyPairEvent PropertyPair = new PropertyPairEvent(strName, strValue);
			OnAddWizardResult(PropertyPair);
		}

		// The protected OnRaiseProperty method raises the event by invoking 
		// the delegates. The sender is always this, the current instance 
		// of the class.
		protected virtual void OnAddWizardResult(PropertyPairEvent e)
		{
			if (e != null)
			{
				// Invokes the delegates. 
				addWizardResultEvent(this, e);
			}
		}

		public bool NextButtonEnabled
		{
			get { return GetAllStates(); }
		}

		public bool NeedSummary
		{
			get { return false; }
		}

		private bool GetAllStates()
		{
			return (Regex.IsMatch(txtAliases.Text, aliasesRegEx));
		}

		private void WzPageTransmitSetup_Leave(object sender, System.EventArgs e)
		{
			AddWizardResult(WizardValues.TransmitAdapterDescription, txtTransmitAdapterDesc.Text);
			AddWizardResult(WizardValues.Aliases, txtAliases.Text);
			AddWizardResult(WizardValues.TransmitAdapterSupportsSolRsp, chkSolRspSupport.Checked.ToString());
			AddWizardResult(WizardValues.TransmitAdapterHasExtendedBatchSupport, chcExtendedBatchSupport.Checked.ToString());
		}

		private void txtAliases_Validating(object sender, System.ComponentModel.CancelEventArgs e)
		{
			EnableNext(GetAllStates());
			if (!Regex.IsMatch(txtAliases.Text, aliasesRegEx) && txtAliases.Text.Length > 0)
			{
				ErrProv.SetError(txtAliases,
					"Text must consist of one or more aliases in format Alias1://, Alias2:// etc.");
			}
			else
			{
				ErrProv.SetError(txtAliases, "");
			}
		}

		#region Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WzPageTransmitSetup));
			this.chkSolRspSupport = new System.Windows.Forms.CheckBox();
			this.label1 = new System.Windows.Forms.Label();
			this.txtTransmitAdapterDesc = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.txtAliases = new System.Windows.Forms.TextBox();
			this.ErrProv = new System.Windows.Forms.ErrorProvider(this.components);
			this.chcSimpleBatchSupport = new System.Windows.Forms.RadioButton();
			this.chcExtendedBatchSupport = new System.Windows.Forms.RadioButton();
			this.grpBatchSupport = new System.Windows.Forms.GroupBox();
			this.panelHeader.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.ErrProv)).BeginInit();
			this.grpBatchSupport.SuspendLayout();
			this.SuspendLayout();
			// 
			// labelTitle
			// 
			resources.ApplyResources(this.labelTitle, "labelTitle");
			// 
			// labelSubTitle
			// 
			resources.ApplyResources(this.labelSubTitle, "labelSubTitle");
			// 
			// chkSolRspSupport
			// 
			resources.ApplyResources(this.chkSolRspSupport, "chkSolRspSupport");
			this.chkSolRspSupport.Name = "chkSolRspSupport";
			// 
			// label1
			// 
			resources.ApplyResources(this.label1, "label1");
			this.label1.Name = "label1";
			// 
			// txtTransmitAdapterDesc
			// 
			resources.ApplyResources(this.txtTransmitAdapterDesc, "txtTransmitAdapterDesc");
			this.txtTransmitAdapterDesc.Name = "txtTransmitAdapterDesc";
			// 
			// label3
			// 
			resources.ApplyResources(this.label3, "label3");
			this.label3.Name = "label3";
			// 
			// txtAliases
			// 
			resources.ApplyResources(this.txtAliases, "txtAliases");
			this.txtAliases.Name = "txtAliases";
			this.txtAliases.Validating += new System.ComponentModel.CancelEventHandler(this.txtAliases_Validating);
			// 
			// ErrProv
			// 
			this.ErrProv.ContainerControl = this;
			resources.ApplyResources(this.ErrProv, "ErrProv");
			// 
			// chcSimpleBatchSupport
			// 
			resources.ApplyResources(this.chcSimpleBatchSupport, "chcSimpleBatchSupport");
			this.chcSimpleBatchSupport.Checked = true;
			this.chcSimpleBatchSupport.Name = "chcSimpleBatchSupport";
			this.chcSimpleBatchSupport.TabStop = true;
			this.chcSimpleBatchSupport.UseVisualStyleBackColor = true;
			// 
			// chcExtendedBatchSupport
			// 
			resources.ApplyResources(this.chcExtendedBatchSupport, "chcExtendedBatchSupport");
			this.chcExtendedBatchSupport.Name = "chcExtendedBatchSupport";
			this.chcExtendedBatchSupport.UseVisualStyleBackColor = true;
			// 
			// grpBatchSupport
			// 
			this.grpBatchSupport.Controls.Add(this.chcExtendedBatchSupport);
			this.grpBatchSupport.Controls.Add(this.chcSimpleBatchSupport);
			resources.ApplyResources(this.grpBatchSupport, "grpBatchSupport");
			this.grpBatchSupport.Name = "grpBatchSupport";
			this.grpBatchSupport.TabStop = false;
			// 
			// WzPageTransmitSetup
			// 
			this.Controls.Add(this.grpBatchSupport);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.txtAliases);
			this.Controls.Add(this.chkSolRspSupport);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.txtTransmitAdapterDesc);
			this.Name = "WzPageTransmitSetup";
			this.SubTitle = "Specify transmit adapter settings";
			this.Title = "Transmit side settings";
			this.Load += new System.EventHandler(this.WzPageTransmitSetup_Load);
			this.Leave += new System.EventHandler(this.WzPageTransmitSetup_Leave);
			this.Controls.SetChildIndex(this.panelHeader, 0);
			this.Controls.SetChildIndex(this.txtTransmitAdapterDesc, 0);
			this.Controls.SetChildIndex(this.label1, 0);
			this.Controls.SetChildIndex(this.chkSolRspSupport, 0);
			this.Controls.SetChildIndex(this.txtAliases, 0);
			this.Controls.SetChildIndex(this.label3, 0);
			this.Controls.SetChildIndex(this.grpBatchSupport, 0);
			this.panelHeader.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.ErrProv)).EndInit();
			this.grpBatchSupport.ResumeLayout(false);
			this.grpBatchSupport.PerformLayout();
			this.ResumeLayout(false);
			this.PerformLayout();

		}
		#endregion

		private void WzPageTransmitSetup_Load(object sender, EventArgs e)
		{
#if DEBUG
			txtTransmitAdapterDesc.Text = "Description for transmit adapter";
			txtAliases.Text = "test1://";
			chkSolRspSupport.Select();
#endif
		}

	}
}

